<template>
  <h1>猜数字练习</h1>
  <input type="text" placeholder="请输入您要猜的数字" v-model="num">
  <button @click="guess">猜一猜</button>
  <h3>您猜的结果是{{num}}</h3>
  <h3>{{result}}</h3>



</template>
<script setup>
import {ref} from "vue";
let x = parseInt(Math.random()*100)+1;
console.log("打个小炒："+x);
const num = ref('');
const result = ref("");
/*const guess = () => {
  if (num!=x){
    result.value = "猜错了";
  }else {
    result.value = "猜对了";
  }
}*/
const guess = () =>{
  if(num.value.trim()==''){
    num.value = '';
    alert('请输入数字!');
    return;
  }
  if(num.value < x){
    result.value = '猜小了';
  }else if(num.value > x){
    result.value = '猜大了';
  }else{
    result.value = '猜对了';
  }
}





</script>
<style scoped>

</style>